home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / cagd_lib / cagdextr.c < prev    next >
C/C++ Source or Header  |  1995-12-30  |  4KB  |  103 lines

  1. /******************************************************************************
  2. * CagdEXTR.c - Extrusion operator out of a given profile and a direction vec. *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Mar. 91.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /*****************************************************************************
  10. * DESCRIPTION:                                                               M
  11. * Constructs an extrusion surface in the Vector direction for the given      M
  12. * profile curve. Input curve can be either a Bspline or a Bezier curve and   M
  13. * the resulting output surface will be of the same type.             M
  14. *                                                                            *
  15. * PARAMETERS:                                                                M
  16. *   Crv:     To exturde in direction specified by Vec.                       M
  17. *   Vec:     Direction as well as magnitude of extursion.                    M
  18. *                                                                            *
  19. * RETURN VALUE:                                                              M
  20. *   CagdSrfStruct *:   An extrusion surface with Orders of the original      M
  21. *                      Crv order and 2 in the extrusion direction.           M
  22. *                                                                            *
  23. * KEYWORDS:                                                                  M
  24. *   CagdExtrudeSrf, surface constructors                                     M
  25. *****************************************************************************/
  26. CagdSrfStruct *CagdExtrudeSrf(CagdCrvStruct *Crv, CagdVecStruct *Vec)
  27. {
  28.     CagdSrfStruct *Srf;
  29.     int i, j,
  30.     MaxCoord = CAGD_NUM_OF_PT_COORD(Crv -> PType),
  31.     Len = Crv -> Length;
  32.     CagdPointType
  33.     PType = Crv -> PType;
  34.     CagdBType
  35.     IsNotRational = !CAGD_IS_RATIONAL_CRV(Crv);
  36.     CagdRType **SrfPoints,
  37.     **CrvPoints = Crv -> Points,
  38.     *Dir = Vec->Vec;
  39.  
  40.     switch (PType) {
  41.     case CAGD_PT_P2_TYPE:
  42.         PType = CAGD_PT_P3_TYPE;
  43.         break;
  44.     case CAGD_PT_E2_TYPE:
  45.         PType = CAGD_PT_E3_TYPE;
  46.         break;
  47.     case CAGD_PT_P3_TYPE:
  48.     case CAGD_PT_E3_TYPE:
  49.         break;
  50.     default:
  51.         CAGD_FATAL_ERROR(CAGD_ERR_UNSUPPORT_PT);
  52.         break;
  53.     }
  54.  
  55.     switch (Crv -> GType) {
  56.     case CAGD_CBEZIER_TYPE:
  57.         Srf = BzrSrfNew(Len, 2, PType);
  58.         break;
  59.     case CAGD_CBSPLINE_TYPE:
  60.         Srf = BspPeriodicSrfNew(Len, 2,
  61.                     Crv -> Order, 2,
  62.                     Crv -> Periodic, FALSE,
  63.                     PType);
  64.         CAGD_GEN_COPY(Srf -> UKnotVector, Crv -> KnotVector,
  65.               sizeof(CagdRType) * (CAGD_CRV_PT_LST_LEN(Crv) +
  66.                            Crv -> Order));
  67.         Srf -> VKnotVector[0] = Srf -> VKnotVector[1] = 0.0;
  68.         Srf -> VKnotVector[2] = Srf -> VKnotVector[3] = 1.0;
  69.         break;
  70.     case CAGD_CPOWER_TYPE:
  71.         CAGD_FATAL_ERROR(CAGD_ERR_POWER_NO_SUPPORT);
  72.         return NULL;
  73.     default:
  74.         CAGD_FATAL_ERROR(CAGD_ERR_UNDEF_CRV);
  75.         return NULL;
  76.     }
  77.  
  78.     /* Copy the control mesh - first row is exactly the same as the curve    */
  79.     /* while second one is the same as first one translated by Vec.          */
  80.     SrfPoints = Srf -> Points;
  81.  
  82.     for (i = IsNotRational; i <= MaxCoord; i++)               /* First row. */
  83.     CAGD_GEN_COPY(SrfPoints[i], CrvPoints[i],
  84.               sizeof(CagdRType) * Len);
  85.  
  86.     /* Make a copy of the Second row do we can "work" on it. */
  87.     for (i = IsNotRational; i <= MaxCoord; i++)              /* Second row. */
  88.     CAGD_GEN_COPY(&SrfPoints[i][Len], CrvPoints[i],
  89.               sizeof(CagdRType) * Len);
  90.  
  91.     /* If the curve has lesser dimension (i.e. was 2D), Add zeros. */
  92.     for (i = MaxCoord + 1; i <= 3; i++)
  93.     for (j = 0; j < Len * 2; j++)
  94.         SrfPoints[i][j] = 0.0;
  95.  
  96.     for (i = 1; i <= 3; i++)            /* Translate the second row. */
  97.     for (j = Len; j < Len * 2; j++)
  98.         SrfPoints[i][j] += IsNotRational ? Dir[i - 1] :
  99.                            Dir[i - 1] * SrfPoints[W][j];
  100.  
  101.     return Srf;
  102. }
  103.